package com.weigongbao.weigongbao;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import uk.co.senab.photoview.PhotoViewAttacher;

public class MyPagerAdapter extends PagerAdapter {
    private ArrayList<String> list;
    private Context context;

    public MyPagerAdapter(ArrayList<String> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.page_view, null);
//        View view = View.inflate(context,R.layout.page_view,null);
        ImageView mPhoto = (ImageView) view.findViewById(R.id.pager_photo);
        Glide.with(context).load(list.get(position)).into(mPhoto);
        PhotoViewAttacher attacher = new PhotoViewAttacher(mPhoto);
        attacher.setZoomable(true);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
        container.removeView((View) object);
    }
}
